<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>科目添加</title>

    <link rel="stylesheet" type="text/css" href="/static/js/layui-v2.5.7/layui/css/layui.css">
    <script type="text/javascript" src="/static/js/layui-v2.5.7/layui/layui.js"></script>
    <script type="text/javascript" src="/static/js/myJs.js"></script>

    <script type="text/javascript">
        layui.use(['form'], function () {
            var form = layui.form;
        })
    </script>


</head>
<body>
<a class="layui-btn layui-btn-primary layui-btn-radius" href="SelectCourse">
    <i class="layui-icon">&#xe65a;</i>
</a>

<form action="InsertCourse" method="post" class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label" for="name">科目名字</label>
        <div class="layui-input-inline">
            <input type="text" name="name" id="name" class="layui-input"
                   placeholder="请输入科目名称" autocomplete="off" required>
        </div>
        <button type="button" onclick="add()" class="layui-btn">确认</button>
    </div>
</form>


<script>
    function add() {
        $.ajax({
            dataType: "json",
            url: "/studentLayer/Course/InsertCourse",
            method: "POST",
            data: {"name": $("#name").val()},
            success: function (data) {
                if (data.code == 0) {

                    layer.msg(data.msg, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.reload(index);
                        window.location.href = "/studentLayer/Course/SelectCourse";
                    });

                } else {
                    layer.msg("添加失败", function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.reload(index);
                        window.location.href = "/studentLayer/Course/SelectCourse";
                    });

                }
            }
        })
    }

</script>


</body>
</html>